#ifndef VERTEX_H
#define VERTEX_H

class   Face;
class Triangle;
class   Shader;
class VertexTemplate;

#include "Troll3D_global.h"
#include "BufferObject.h"
#include "GeoTool/vec4.h"
#include "VertexTemplate.h"
#include "Triangle.h"
#include <QDebug>

#include <memory.h>
#include <vector>

using namespace std;

/*!	@brief The Vertex class define the structure of vertex attributes send to the shaders, and the way to interact with them
 *
 *          Workflow overview : A mesh is constitued by vertices. All the vertex a Mesh need will be stored in only one
 *          vector : the static propertie Vertices in Vertex.
 *          When a mesh want to create a new Vertex, it'll have to call the static method "New", this will automatically add the vertex
 *          in the Vertices vector, and give back a pointer for the mesh
 *          To render the scene, the vertex must be given to a VBO as float *. So, there'll be a phase where all the vertex will be
 *          inspected and transformed in float * . During this phase, the m_Indice must be defined, for the IBO to work correctly
 */

class TROLL3DSHARED_EXPORT Vertex
{
    /************************************************
    /*				Public
    /************************************************/
     public :

        /************************************************
        /*				Constructors
        /************************************************/

            /*! @brief Utilisera le VertexTemplate par défault   */
            Vertex();
            Vertex(VertexTemplate & vt);

        /************************************************
        /*				Methods
        /************************************************/

            /*! @brief A faire plus tard : Devra "effacer" les buffer et rallouer le bon nombre de
             *  float dans VerticeBuffer    */
            void SetTemplate(VertexTemplate * vertexTemplate);

            void        ComputeNormal();


        /************************************************
        /*				Get/Set
        /************************************************/

            bool SetAttribute(string name, float x);
            bool SetAttribute(string name, float x, float y);
            bool SetAttribute(string name, float x, float y, float z);
            bool SetAttribute(string name, float x, float y, float z, float w);

            bool SetAttribute(int pos, float x);
            bool SetAttribute(int pos, float x, float y);
            bool SetAttribute(int pos, float x, float y, float z);
            bool SetAttribute(int pos, float x, float y, float z, float w);


            int     offset();
            int     size();
            int     attributeCount();

            const VertexTemplate &  vertexTemplate();

        /************************************************
        /*				Properties
        /************************************************/

            /*! @brief Identifiant permettant aux tableau d'indice de retrouver le vertex */
            int    vertexId;

         /************************************************/
         /*				Statics Methods
         /************************************************/

            static  void        DeleteVertex(int pos);
            static  float *     Array();
            static  void        Debug();

         /************************************************/
         /*				Statics Properties
         /************************************************/

            static     vector<GLfloat>      BufferVertices;
            static     vector<Vertex *>     Vertices;

            static     int  s_Offset;

    /************************************************
    /*				Private
    /************************************************/
    private :

        /************************************************
        /*				Methods
        /************************************************/

            void UpdateVertex();

            /*! @brief Alloue l'espace nécéssaire à l'intérieur du VerticeBuffer    */
            void AllocateBuffer();


        /************************************************
        /*				Properties
        /************************************************/

            int                     m_Offset;
            int                     m_Size;

            VertexTemplate *        m_VertexTemplate;
            vector<Triangle *>      m_Triangles;


};

#endif
